<?php

    require_once($application_folder."/controllers/navigator.php");
    class image extends Navigator {

        function image () {
            parent::navigator();

            $this->title("Upload fotografije");

            // load models
            $this->load->model('excursions/excursions_m','excursions_m');
            $this->load->model('tours/tours_m','tours_m');
            $this->load->model('image_m','imagem');

            // load library
            $this->load->library('upload');
            $this->load->library('image_lib');
            $this->data['p'] = '';  
            $this->data['language'] = $this->lang_ses->getLang();
            
            /*Class*/
            $this->load->library('translate');
                
            //set local language
            $this->translate->setLang($this->lang_ses->getLang());
        }// construct of image

        function index() {
            
            $this->usersm->check_log(1);

        }

        function addnew_form($id) {

            $this->data['excursion'] = $this->excursions_m->read($id);
            $this->data['images'] = $this->db->get_where('excimg',array('excursions_id' => $id))->result_array();

            $this->navigate('image/addnew_form_excursion_v');
        }
        
        function delete_excimg($id,$excid){
            
            
            $this->db->where('id',$id);
            $this->db->delete('excimg');
            
            redirect(site_url().'image/addnew_form/'.$excid);
            
        }
        function delete_tourimg($id,$tourid){
            
            
            $this->db->where('id',$id);
            $this->db->delete('tourimg');
            
            redirect(site_url().'image/addnew_form_tours/'.$tourid);
            
        }

        function addnew_form_tours($id) {

            $this->data['tour'] = $this->tours_m->read($id);
            $this->data['images'] = $this->db->get_where('tourimg',array('tours_id' => $id))->result_array();

            $this->navigate('image/addnew_form_tours_v');         
        }

        function submit_addnew() {

            $response = $this->imagem->create('excursions');

            if($response['success'] == 'success') {

                $this->data['response'] = $response;

                //$this->navigate('image/success_v');
                redirect(site_url().'image/addnew_form/'.$this->input->post('excursion_id')); 

            }else {

                $this->data['excursion'] = $this->excursions_m->read($this->input->post('excursion_id'));
                $this->data['images'] = $this->db->get_where('excimg',array('excursions_id' => $this->input->post('excursion_id')))->result_array();
                $this->data['response'] = $response;
                $this->data['submit'] = TRUE;

                $this->navigate('image/addnew_form_excursion_v');  

            }
        }

        function submit_addnew_tours() {

            $response = $this->imagem->create('tours');

            if($response['success'] == 'success') {

                $this->data['response'] = $response;

                //$this->navigate('image/success_v');
                redirect(site_url().'image/addnew_form_tours/'.$this->input->post('tour_id'));

            }else {

                $this->data['tour'] = $this->tours_m->read($this->input->post('tour_id'));
                $this->data['images'] = $this->db->get_where('tourimg',array('tours_id' => $this->input->post('tour_id')))->result_array();
                $this->data['response'] = $response;
                $this->data['submit'] = TRUE;

                $this->navigate('image/addnew_form_tours_v'); 

            }
        }

    }
?>